import subprocess


def start_mysql_service():
    try:
        # 使用 sc 命令启动 MySQL 服务
        result = subprocess.run(['sc', 'start', 'MYSQL80'], capture_output=True, text=True)

        if "The specified service has been marked for deletion." not in result.stderr and "The service is already running." not in result.stdout:
            if "SUCCESS" in result.stdout:
                print("MySQL 服务已启动。")
            else:
                print(f"启动 MySQL 服务失败。错误信息: {result.stderr}")
                print(f"启动 MySQL 服务失败。错误信息: {result.stdout}")
        else:
            print("MySQL 服务已经在运行或已被标记为删除。")
    except Exception as e:
        print(f"发生错误: {e}")


if __name__ == "__main__":
    start_mysql_service()